package com.ds.infrastructure.audit.admin.security;

import com.ds.infrastructure.audit.admin.entry.UserInfo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * 作用：
 *
 * @author WeiShaoying
 * @date 2020/8/10
 */
public class SidAuthenticationToken extends AbstractAuthenticationToken {

    private static final long serialVersionUID = -4912802957121287382L;

    @Getter
    @Setter
    private String sid;

    @Getter
    @Setter
    private UserInfo userInfo;

    SidAuthenticationToken(String sid) {
        super(null);
        this.sid = sid;
    }

    SidAuthenticationToken(UserInfo userInfo, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        super.setAuthenticated(true);
        this.userInfo = userInfo;
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public UserInfo getPrincipal() {
        return userInfo;
    }


    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
    }
}
